<style>
	* {padding:0px;margin:0px;box-sizing:border-box;outline:none;}
	.header{width:100%;}
	.header .header_info{display: table;margin:0 auto;	max-width: 1200px;width: 100%;}
	.header .header_info .left {text-align: left;display: table-cell;}
	.header .header_info .right {text-align: right;display: table-cell;vertical-align:middle;margin-right:20px;}
	.header .header_info .right .text {border:3px solid #ff4401;width:420px;height:30px;background:#fff;padding-left:80px;color:#666}
	.header .header_info .right .sub {width:80px;height:30px;background:#ff4401;color:#fff;font-family:微软雅黑;font-weight:bold;letter-spacing:10px;text-align:center;border:1px solid #ff4401;cursor:pointer;}
	.header .header_info .right .sel {width:80px;height:25px;position:relative;left:82px;border:none;background:#f5f5f5;color:#666;padding-left:5px;}

	.title{margin-top:20px;}
	.title .nav_cart {width:1200px;margin:0 auto;}
	.nav_cart ul{border-bottom:1px solid #ccc;}
	.nav_cart ul li{display:inline-block;padding:10px;}
	.nav_cart ul li a{text-decoration:none;color:#000;font-weight:bold;}
	.nav_cart ul li em{font-style:normal;color:#ccc}
	
	.cart .cart_detail{width:1200px;margin:0 auto;}
	table{font-size:12px;}
	table tr td{padding:10px;}	
	table tr td a img{border:1px solid #ccc;float:left;margin-right:10px;}	
	table tr td p {text-align:left;}	
	table tr td p a{text-decoration:none;color:#111;}	
	table tr td p a:hover{text-decoration:underline;color:#ff4401;}	
	table .td1{width:400px;text-align:center;}	
	table .td1 em{font-style:normal;}	
	table .td2{width:100px;text-align:center;}	
	table .td3{width:100px;text-align:center;}	
	table .td4{width:200px;text-align:center;}	
	table .td5{width:200px;text-align:center;}	
	
	
	table .gd1{width:100px;text-align:center;}	
	table .gd1 em{font-style:normal;}	
	table .gd2{width:100px;text-align:center;}	
	table .gd3{width:100px;text-align:center;}	
	table .gd4{width:480px;text-align:center;}	
	table .gd5{width:180px;text-align:center;}	
	table  td a{text-decoration:none;color:#000}	
	table  td a:hover{color:#ff4401}	
	table .gd6 input{background:#ff4401;width:100px;color:#fff;font-size:20px;text-align:center;font-family:微软雅黑;letter-spacing:2px;border:none;height:40px;}	
	table .gd6 input:hover{cursor:pointer;}	
	
	
	
	.count{width:20px;}
	.minus{ width:20px;background:#f0f0f0;border:none;cursor:pointer}	
	.minus:hover{ border:1px solid #ff4401;color:#ff4401}	
	.plus{width:20px;background:#f0f0f0;border:none;cursor:pointer}	
	.plus:hover{border:1px solid #ff4401;color:#ff4401}	
	.text_box{width:30px;border:none;border:1px solid #ccc;color:#333}
</style> 
<script>
	$(function (){
		
		
		
		setTotal();
			$("input").blur(function(){
				setTotal();
			})
			$(".plus").click(function(){
				
				var text_value = $(this).parent().find('input[class=text_box]');
				if(!isNaN(text_value)) alert('不是数字');
					text_value.val(parseInt(text_value.val()) + 1);
				setTotal();

			})
			$(".minus").click(function(){
				
				var text_value = $(this).parent().find('input[class=text_box]');
				if(text_value.val() > 0)
					text_value.val(parseInt(text_value.val()) - 1);
				setTotal();
				

			})
			

		$(".selectall").click(function (){
				if($(this).is(':checked')){
					$("input[class*='che']").each(function(){
						$(this).prop("checked",true);
						$(".selectall").prop("checked",true);
						setTotal();
					})
					
				}else{
					$("input[class*='che']").each(function(){
						$(this).prop("checked",false);
						$(".selectall").prop("checked",false);
						setTotal();
					})
				}
		})
			
		$("#reverse").click(function(){
			$(".selectall").attr("checked",false);
			$("input[class*='che']").each(function(){
				if($(this).prop("checked")){
					$(this).prop("checked", false); 
				}
				else{
					$(this).prop("checked", true); 
				}
			})

			setTotal();
		})
		
		$(".che").click(function(){
			setTotal();
		})

		function setTotal(){
				var s=0; 
				var count = 0;
			    $("table[class *= tt]").each(function(){
			      if($(this).find("input[class *= 'che']").is(":checked")){
				      s+=parseInt($(this).find('input[class*=text_box]').val())*parseFloat($(this).find('td[class*=td3]').text()); 
				      count += parseInt($(this).find('input[class*=text_box]').val());
			      }
			    }); 
			    if(count <= 0){
					$("#pay").css("background","#e1e1e1");
					$("#pay").attr("disabled","true");
					$("#pay").val("无商品");
				}else{
					$("#pay").css("background","#ff4401");
					$("#pay").removeAttr("disabled");
					$("#pay").val("结 算");
				}
				$("#price").html(s.toFixed(2)); 
			    $("#count").html(count);
			}
			$(".del").click(function (){
				var id = $(this).attr("id");
				var table_id = $(".tt").attr("id");
				$.ajax({
					url:'./index.php?r=order/cartdel&goods_id='+id,
					type:'post',
					data:{"type":"delpro"},
					success:function(data){
						if(data == 1){
							$('.tt[id='+table_id+']').remove();
						}else{
							alert('移出购物车失败');
						}
					},
					error:function (){
						alert('操作失败');
					}
				});
			})

			$("#update").click(function (){
//				var formdata = $("#f").serializeArray();
//				alert(formdata);
//				$.ajax({
//					url:'./index.php?r=order/cartupd',
//					type:'post',
//					data:{"type":"updpro","aa":formdata},
//					success:function(data){
//						alert(data);
//						if(data == 1){
//							alert('更新成功');
//						}else{
//							alert('更新失败');
//						}
//					},
//					error:function (){
//						alert('操作失败');
//					}
//				});
//				window.location.reload();
			})
			$.fn.serializeObject = function() { 
				var o = {}; 
				var a = this.serializeArray(); 
					$.each(a, function() { 
						if (o[this.name]) { 
							if (!o[this.name].push) { 
							o[this.name] = [ o[this.name] ]; 
							} 
							o[this.name].push(this.value || ''); 
						} else { 
							o[this.name] = this.value || ''; 
						} 
					}); 
				return o; 
			} 

		$("#pay").click(function (){
			
				window.location.href="./index.php?r=order/account";
		
			
		})

		$(".tt tr td input:checkbox").click(function (){
//			if($(this).attr("value") == 0){
//				$(this).attr("value",1);
//			}else{
//				$(this).attr("value",0);
//			}

		})
			
	})
</script>

<div class="header">
	<div class="header_info">
		<div class="left">
			<div class="box"><a href="#"><img src="<?php echo  IMG_URL?>cart_logo.png" /></a></div>
		</div>
		<div class="right">	
			<div class="box">
				<select class="sel"><option value="1">商品</option><option value="2">店铺</option></select><input type="text" name="search"  class="text" /><input type="submit" name="send" value="搜索" class="sub" />
			</div>
		</div>
	</div>
</div>
 <div class="title">
 	<div class="nav_cart">
	 	<ul >
	 		<li><a href="#" style="color:#ff4401">全部商品</a>　<em>|</em></li>
	 		<li><a href="#">降价商品</a>　<em>|</em></li>
	 		<li><a href="#">库存紧张</a></li>
	 	</ul>
 	</div>
 </div>
 <div class="cart">
 	<div class="cart_detail">
	 	<table >
	 		<tr >
	 			<td style="width:120px;"><input type="checkbox" style="vertical-align:middle;text-align:left" class="selectall" name="selectall" />全选</td>
	 			<td class="td1">商品信息</td>
	 			<td class="td2">店铺信息</td>
	 			<td class="td3">单价(元)</td>
	 			<td class="td4">数量	</td>
	 			<td class="td5" ></td>
	 			<td class="td6">操作</td>
	 		</tr>
	 	</table >
	 	
	 	<form action="./index.php?r=order/cartupd"  method="post" id="f" />
 		<?php foreach($cart_info as $_v){?>
	 	
	 	<table  class="tt" style="border:1px solid #ccc;background:#fcfcfc;margin-top:-20px;"  id="<?php echo $_v['goods_id']?>" >
			<tr>
	 			<td style="width:120px;text-align:right;"><input type="checkbox" <?php if($_v['active'] == 1) echo "checked='checked'";?>  value="<?php echo $_v['goods_id'];?>"    class="che"  style="vertical-align:middle;text-align:left;"  name="active[]"   /></td>
	 			<td class="td1"><a href="#"><img style="text-align:left;" src="<?php echo $_v['goods_thumbnail_url']?>" width="89" height="89" /></a><p><a href="#"><?php echo $_v['goods_name']?></a></p></td>
				<td class="td2"><?php echo $_v['brand_id']?></td>
				<td class="td3" id="per"><?php echo $_v['goods_price']?></td>
				<td class="td4">
					<input type="button" value="-" class="minus"/>
					<input type="hidden" name="goods_ids[]" value="<?php echo $_v['goods_id']?>"  />
 					<input type="text" class="text_box" name="cart_goods_count[]"  value="<?php echo $_v['cart_goods_count']?>"   />
					<input type="button" value="+" class="plus"   />
				</td>
				<td class="td5" ><em class="total"></em></td>
				<td class="td6" ><a class="del" id="<?php echo $_v['goods_id']?>" href="javascritp:void(0);" >移出购物车</a></td>
			</tr>	 	
	 	</table>
	 	<?php }?>
	 	
	
	 	
	 	<table style="background:#e5e5e5" id="6">
	 		<tr >
	 			<td style="width:140px;">
	 				<input type="checkbox" style="vertical-align:middle;text-align:left" class="selectall" name="selectall" />全选
	 				<input type="button" id="reverse" name="reverse" value="反选" style="background:#ccc;border:none;padding:3px;color:#fff;font-size:8px;" />
	 			</td>
	 			<td class="gd1"><a href="#" >删除</a></td>
	 			<td class="gd2"><a href="#">移入收藏夹</a></td>
	 			<td class="gd3"><a href="#" >共享</a></td>
	 			<td class="gd4" >已选<i style="color:#ff4401;font-style:normal;font-size:15px;font-weight:bold;" id="count">0</i>件</td>
	 			<td class="gd5" >合计(不含运费)<i style="color:#ff4401;font-style:normal;font-size:15px;font-weight:bold;">￥<em style="font-style:normal;" id="price">0.00</em></i></td>
	 			<td class="gd6" >
		 			<input type="submit" id="update"  value="更新购物车" style="background:#ccc;border:none;padding:3px;color:red;font-size:8px;" name="send"  />
		 			<input type="button" id="pay"  value="结 算"   />
	 			</td>
	 		</tr>
	 	</table >
	 	</form>
 	</div>
 </div>
